package com.example.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringCloudApplication
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }


    @Bean
    public RouteLocator getRouter(RouteLocatorBuilder builder) {
        return builder
                .routes()
                .route(router -> router
                        .path("/client/**")
                        .filters(gatewayFilterSpec -> gatewayFilterSpec.stripPrefix(1)) //去除前缀
                        .uri("lb://eureka-client"))
                .route(router -> router
                        .path("/customer/**")
                        .filters(gatewayFilterSpec -> gatewayFilterSpec.stripPrefix(1))
                        .uri("lb://customer"))
                .route(router -> router
                        .path("/eureka-server/**")
                        .filters(gatewayFilterSpec -> gatewayFilterSpec.stripPrefix(1))
                        .uri("lb://eureka-server"))
                .route(router -> router.path("/eureka/**")
                                       //.filters(gatewayFilterSpec -> gatewayFilterSpec.stripPrefix(1))
                                       .uri("lb://eureka-server"))
                .build();
    }
}
